<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<script>

    var sum=[2,5,6,7,3,4,1];
    for(var i=0;i<=sum.length-1;i++){
        for(var j=0;j<=sum.length-i-1;j++){
            if(sum[j]>sum[j+1]){
                // if(sum[j]<sum[j+1])  从大到小排序
                var temp=sum[j];
                sum[j]=sum[j+1];
                sum[j+1]=temp;
            }
        }
    }
    console.log(sum);




     //;冒泡排序函数封装
     function arr(arrs) {
            for (var i = 0; i <= arrs.length - 1; i++) {
                for (var j = 0; j <= arrs.length - i - 1; j++) {
                    if (arrs[j] > arrs[j + 1]) {
                        temp = arrs[j];
                        arrs[j] = arrs[j + 1]
                        arrs[j + 1] = temp
                    }
                }
            }
            return arrs;
        }
        var hh = arr([7, 4, 6, 3, 2, 9, 1, 8, 5])
        console.log(hh);
</script>
</body>
</html>